home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Utilities / Type1Manager / src / amishio.c < prev    next >
C/C++ Source or Header  |  1996-07-12  |  2KB  |  146 lines

  1. /*******************************************************************
  2. *  Amish's I/O package for Type 1 font reading
  3. ********************************************************************/
  4.  
  5. #ifndef T1GST
  6. #include "global.h"
  7. #endif
  8.  
  9.  
  10. extern void freefont(char *fbuf);
  11. extern int readfont(char *filename, char **pfbuf, int *pfbuflen);
  12.  
  13.  
  14. /* Open the file */
  15. F_FILE *T1Open(char *fn, char *mode)
  16. {
  17.     F_FILE *of;
  18.  
  19.     if (of = (F_FILE *)xalloc(sizeof(F_FILE)))
  20.     {
  21.         if (readfont(fn, &(of->fbuf), &(of->fbuflen)) >= 0)
  22.         {
  23.             of->curpos = 0;
  24.             return of;
  25.         }
  26.  
  27.         xfree(of);
  28.         of = NULL;
  29.     }
  30.  
  31.     return of;
  32. }
  33.  
  34.  
  35. /* Read one character */
  36. int T1Getc(F_FILE *f)
  37. {
  38.     if (f->fbuf == NULL)
  39.         return EOF;            /* already closed */
  40.  
  41.     if (f->curpos == f->fbuflen)
  42.         return EOF;
  43.  
  44.     return (f->fbuf)[(f->curpos)++];
  45. }
  46.  
  47.  
  48. /* Put back one character */
  49. int T1Ungetc(int c, F_FILE *f)
  50. {
  51.     if (f && (c != EOF))
  52.     {
  53.         if (f->curpos > 0)
  54.             (f->curpos)--;
  55.     }
  56.  
  57.     return c;
  58. }
  59.  
  60.  
  61. /* Read n items into caller's buffer */
  62. int T1Read(char *buffP, int size, int n, F_FILE *f)
  63. {
  64.     int acnt, rcnt;
  65.  
  66.     /* Number of bytes requested */
  67.     rcnt = n * size;
  68.  
  69.     /* Number of bytes available */
  70.     acnt = f->fbuflen - f->curpos;
  71.  
  72.     if (rcnt <= acnt)
  73.     {
  74.         memcpy((void *)buffP, (void *)(f->fbuf + f->curpos), rcnt);
  75.         (f->curpos) += rcnt;
  76.         return rcnt;
  77.     }
  78.     else
  79.     {
  80.         memcpy((void *)buffP, (void *)(f->fbuf + f->curpos), acnt);
  81.         (f->curpos) = f->fbuflen;
  82.         return acnt;
  83.     }
  84. }
  85.  
  86.  
  87. /* Close the file */
  88. int T1Close(F_FILE *f)
  89. {
  90.     if (f)
  91.     {
  92.         freefont(f->fbuf);
  93.         xfree(f);
  94.     }
  95.  
  96.     return 1;
  97. }
  98.  
  99.  
  100. /**
  101.  * I commented out the following C version of T1eexec() because I have now
  102.  * implemented it in assembly...
  103.  **/
  104.  
  105. /* Eexec Decryption */
  106. //F_FILE *T1eexec(F_FILE *f)
  107. //{
  108. //    int i, c;
  109. //    unsigned char ch;
  110. //    unsigned char randomP[4];
  111. //    unsigned short r;
  112. //    int pos;
  113. //    static unsigned short c1 = 52845;
  114. //    static unsigned short c2 = 22719;
  115. //
  116. //    /**
  117. //     * Get and initialize the key
  118. //     **/
  119. //    randomP[0] = (f->fbuf)[(f->curpos)++];
  120. //    randomP[1] = (f->fbuf)[(f->curpos)++];
  121. //    randomP[2] = (f->fbuf)[(f->curpos)++];
  122. //    randomP[3] = (f->fbuf)[(f->curpos)++];
  123. //    r = 55665;
  124. //    for (i=0; i < 4; i++)
  125. //        r = (randomP[i] + r) * c1 + c2;
  126. //
  127. //    /**
  128. //     * Store the current file position
  129. //     **/
  130. //    pos = f->curpos;
  131. //
  132. //    /**
  133. //     * Decrypt the rest of the file.  NOTE: ascii is not supported at this time
  134. //     **/
  135. //    while (pos != f->fbuflen)
  136. //    {
  137. //        c = (f->fbuf)[pos];
  138. //        ch = c ^ (r >> 8);
  139. //        r = (c + r) * c1 + c2;
  140. //        (f->fbuf)[pos++] = ch;
  141. //    }
  142. //
  143. //    return f;
  144. //}
  145.  
  146.